var UglifyJS = require('uglify-js');
var fs = require('fs');

fs.readFile('./src/jsencrypt.js', 'utf8', function(readErr, data) {
  if (readErr) {
    throw readErr;
  }
  var result = UglifyJS.minify(data);
  if (result.error) {
    console.error('minify error:', result.error);
  } else {
    fs.writeFile('./index.js', result.code, 'utf8', function(writeErr) {
      if (writeErr) {
        throw writeErr;
      }
      console.log('build success');
    });
  }
});
